home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
progem.lzh
/
wind12.prf
< prev
next >
Wrap
Text File
|
1987-06-23
|
18KB
|
385 lines
.!****************************************************************************
.!
.! ANTIC PUBLISHING INC., COPYRIGHT 1985. REPRINTED BY PERMISSION.
.!
.! ** Professional GEM ** by Tim Oren
.!
.! Proff File by ST enthusiasts at
.! Case Western Reserve University
.! Cleveland, Ohio
.! uucp : decvax!cwruecmp!bammi
.! csnet: bammi@case
.! arpa : bammi%case@csnet-relay
.! compuserve: 71515,155
.!
.!****************************************************************************
.!
.!
.!****************************************************************************
.!
.! Begin Part 12
.!
.!****************************************************************************
.!
.PART XII GEM Events and Program Structure
.PP
So I fibbed a little. This issue (#12) of ST PRO GEM started
out to be another discussion of interface issues. But, as Tolkien
once said, the tale grew in the telling, and this is now the first
of a series of three articles. This part will discuss AES event
handling and its implications for GEM program structure. The
following article will contain a "home brew" dialog handler with
some new features, and the third will, finally, take up the
discussion of interface design, using the dialog handler as an
example. (There is no download for this article. The downloads
will return, with a vengeance, in ST PRO GEM #13.)
.SH ALL FOR ONE, AND ONE FOR ALL.
A quick inspection of the AES
documents shows that there are five routines devoted to waiting
for individual types of events, and one routine, evnt_multi, which
is used when more than one type is desired. This article will
discuss ONLY evnt_multi for two reasons. First, it is the most
frequently used of the routines. Second, waiting for one type of
event is a bad practice. Any event call turns the system over to
the AES and suspends the application and its interaction with the
user. In such cases, some "escape clause", such as a timer,
should be inserted to revive the program and prompt the user if no
event is forthcoming. Otherwise, the application may end up
apparently (or actually) hung, with a resulting reboot, and
probably a very annoyed user.
.SH STARTING AHEAD.
One possible type of event is a message.
Messages are usually sent to the application by the AES, and are
associated with windows or the menu. Two previous articles in
this series have discussed such messages. ST PRO GEM number two
considered window messages, and number seven handled menu
messages. You may want to review these topics before proceeding.
.PP
The actual evnt_multi call is a horrendous thing:
.FB evnt_multi()
ev_which = evnt_multi(ev_flags,
btn_clicks, btn_mask, btn_state,
r1_flags, r1_x, r1_y, r1_w, r1_h,
r2_flags, r2_x, r2_y, r2_w, r2_h,
&msg_buff,
time_lo, time_hi,
&mx, &my, &btn, &kbd, &char, &clicks);
.FE
Each of the lines in the call relate to a different event, and
they will be discussed in the order in which they appear.
.PP
Note that a call with this number of parameters causes some
overhead stacking and retrieval of the values. In most
cases, this should be of little concern on a machine as fast as
the ST. However, where throughput is a concern, such as in close
tracking of the mouse cursor, you may want to write a customized
binding for evnt_multi which dispenses with the parameter list.
This can be accomplished by maintaining the values in a static
array and moving them as a block into the binding arrays int_in
(for all values but &msg_buff), and addr_in (for &msg_buff). Note
that you may NOT simply leave the values in int_in; other AES
bindings reuse this space.
.PP
Ev_flags and ev_which are both 16-bit integers composed of
flag bits. Bits set in ev_flags determine which event(s) the call
will wait for; those set in ev_which indicate what event(s)
actually occurred. Both use the following flag bit mnemonics and
functions:
.BO
0x0001 - MU_KEYBD - Keyboard input
.EO
.BO
0x0002 - MU_BUTTON - Mouse button(s)
.EO
.BO
0x0004 - MU_M1 - Mouse rectangle #1
.EO
.BO
0x0008 - MU_M2 - Mouse rectangle #2
.EO
.BO
0x0010 - MU_MESAG - AES message
.EO
.BO
0x0020 - MU_TIMER - Timer
.EO
.sp 1
The appropriate mnemonics are ORed together to create the proper
ev_flags value.
.PP
There is one common pitfall here. Notice that multiple
events may be reported from one evnt_multi. Event merging is
performed by the AES in order to save space on the application's
event queue. If events have been merged, more than one bit will
be set in the ev_which word. Your application must check ALL of
the bits before returning to a new evnt_multi call. If you
don't do this, some events may be effectively lost.
.PP
The first event to be considered is the mouse button. This
is probably the most difficult event to understand and use, and it
has one major shortcoming.
.PP
The parameter btn_clicks tells GEM the maximum number of
clicks which you are interested in seeing. This value is usually
two, if your program uses the double-click method, or one if only
single clicks are used. The AES returns the number of clicks
which caused the event through &clicks, which must be a pointer to
a word.
.PP
GEM determines the number of clicks by the following method.
When the first button-down is detected, a time delay is begun. If
another complete button-up, button-down cycle is detected before
the time expires, then the result is a double click. Otherwise,
the event is a single click. Note that the final state of the
buttons is returned via &btn, as described below. By checking
this final state, you may determine whether a single click event
ended with the button up (a full click), or with the button still
down (which may be interpreted as the beginning of a drag
operation). Double clicking is meaningless, and not checked, if
the evnt_multi is waiting on more than one button (see below).
.PP
The double-click detection delay is variable, and may be set
by your program using the call
.FB ev_dclick()
ev_dspeed = ev_dclick(ev_dnew, ev_dfunc);
.FE
Ev_dfunc is a flag which determines the purpose of the call. If
it is zero, the current double click speed is returned in
ev_dspeed. If ev_dfunc is non-zero, then ev_dnew becomes the new
double-click speed. Both ev_dspeed and ev_dnew are words
containing a "magic number" between zero and four. Zero is the
slowest (i.e., longest) double-click, and four is the fastest.
(These correspond to the slow-fast range in the Desktop's
Preferences dialog.) In general, you should not reset the click
speed unless specifically requested, because such a change can
throw off the user's timing and destroy the hand/eye coordination
involved in using the mouse.
.PP
GEM was originally designed to work with a single button
input device. This allows GEM applications interaction well with
devices such as light pens and digitizing tablets. However, some
features are available for dealing with multi-button mice like the
ST's.
.PP
The evnt_multi parameters btn_mask and btn_state are words
containing flag bits corresponding to buttons. The lowest order
bit corresponds to the left-most button, and so on. A bit is set
in the btn_mask parameter if the AES is to watch a particular
button. The corresponding bit in btn_state is set to the value
for which the program is waiting. The word returned via &btn
uses the same bit system to show the state of the buttons at
completion. It is important to notice that all of the target
states in btn_state must occur SIMULTANEOUSLY for the event to be
triggered.
.PP
Note the limiting nature of this last statement. It prevents
a program from waiting for EITHER the left or right button to be
pressed. Instead, it must wait for BOTH to be pressed, which is a
difficult operation at best. As a result, the standard mouse
button procedure is practically useless if you want to take full
advantage of both buttons o